<template>
  <div class="admin-article-add">
    <div class="admin-article-add-nav">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/admin/index/home' }"
          ><i class="el-icon-s-home"> 首页</i></el-breadcrumb-item
        >
        <el-breadcrumb-item
          ><a href="/admin/index/articlelist"
            ><i class="el-icon-document">文章列表</i></a
          ></el-breadcrumb-item
        >
        <el-breadcrumb-item
          ><a href="/admin/index//article/add"
            ><i class="el-icon-document-add">添加文章</i></a
          ></el-breadcrumb-item
        >
      </el-breadcrumb>
    </div>
    <div class="admin-article-add-main">
      <div class="title">添加商品</div>
      <div class="admin-pro-list-add-pro-main">
        <table>
          <tbody>
            <tr>
              <td>文章标题</td>
              <td>
                <input type="text" v-model="title" maxlength="20" />
              </td>
            </tr>
            <tr>
              <td>文章副标题</td>
              <td>
                <input
                  class="sketch"
                  type="text"
                  v-model="sketch"
                  maxlength="50"
                />
              </td>
            </tr>
            <tr>
              <td>文章内容<br />(html格式)</td>
              <td>
                <textarea v-model="content"></textarea>
              </td>
            </tr>
          </tbody>
        </table>
        <div class="admin-pro-list-add-pro-btn">
          <el-button v-model="article" type="success" @click="subArticle"
            >提交</el-button
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
export default {
  data() {
    return {
      title: "",
      sketch: "",
      content: "",
      article: "",
    };
  },
  methods: {
    subArticle() {
      var url = `article/insert`;
      var arttime = moment().format("YYYY年MM月DD日 kk:mm");
      var params = `title=${this.title}&sketch=${this.sketch}&arttime=${arttime}&content=${this.content}`;
      this.axios
        .post(url, params)
        .then((res) => {
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: res.data.msg,
            });
            this.title = "";
            this.sketch = "";
            this.content = "";
          } else {
            message({ type: "error", message: res.data.msg });
          }
        })
        .catch((err) => {
          this.$message({
            type: "warning",
            message: err.data.msg,
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.admin-article-add {
  .admin-article-add-main {
    margin-top: 20px;
    .title {
      background-color: rgba(202, 199, 199, 0.4);
      padding: 8px;
    }
    .admin-pro-list-add-pro-main {
      table {
        // border: 1px solid gray;
        width: 100%;
        text-align: center;
        margin-top: 10px;
        tr {
          td:first-child {
            text-align: right;
          }
          td:last-child {
            text-align: left;
            padding: 10px;
            input {
              width: 300px;
              padding: 10px;
              border: 1px solid #333;
              border-radius: 4px;
            }
            input.sketch {
              width: 600px;
            }
            textarea {
              width: 600px;
              height: 400px;
              word-wrap: break-word;
              border-radius: 8px;
              border: 1px dashed #333;
              font-size: 14px;
              line-height: 20px;
              padding: 4px;
            }
          }
        }
      }
    }
    .admin-pro-list-add-pro-btn {
      margin-left: 150px;
    }
  }
}
</style>
